< previous page page_131 next page >

Page 131
Because the object variable, NewNoteObj, is defined as an object, it can be set to whatever object you must create for the application.
Acting on Objects and Collections
As you add more controls to a form, working with these controls becomes a little cumbersome. Because the same types of objects are members of the same class (that is, every text box on a form is a member of the text box class, sharing properties), you are able to program these objects with more flexibility than you would have thought. As an example, look at a section of code that you would normally see in almost every application. This code sets several properties for a single object, a text box. In the following code, you can see that the control name is duplicated on every line:
txtFirstName.Text = Demo
txtFirstName.Font = Ariel
txtFirstName.BackColor = vbRed
TxtFirstName.FontBold = True
TxtFirstName.FontSize = 12
By using the With-End With command set you can easily set several properties for the same object. The preceding code could be rewritten as:
With txtFirstName
    .Text = Demo
    .Font = Ariel
    .BackColor = vbRed
    .FontBold = True
    .FontSize = 12
End With
Later today you will see how to use this command in conjunction with collections to reduce the amount of code in your application and increase the performance at the same time.
Most collections that you will use in your applications will be created, destroyed, and managed by Visual Basic itself. They will take one of the following forms:
Forms
Controls
Grid columns and rows
List items
TreeView nodes
Data recordset fields
Others

 
< previous page page_131 next page >

If you like this book, buy it!